#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[100005];

signed main() {
	int n, x;
	cin >> n >> x;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] > x) {
			ans += a[i] - x;
			a[i] = x;
		}
	}
	for (int i = 2; i <= n; i++) {
		if (a[i] + a[i - 1] > x) {
			ans += a[i] + a[i - 1] - x;
			a[i] = x - a[i - 1];
		}
	}
	cout<<ans;
	return 0;
}
